<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page language="java" import="com.server.web.JsVersionUtil"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>${formTitle}</title>
<script type="text/javascript"
	src='<c:url value="/js/boot.js"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>'></script>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>?v=<%=JsVersionUtil.CURRENT_VERSION%>' />
<style type="text/css"> 
body {
	height: 100%;
}

.formOutter {
	width: 700px;
	margin: 10px auto;
}
.frametable{
	width: 700px;
}

.formOutter .taskForm {
	border: 1px solid lightgray;
	background-color: white;
	padding: 8px;
	padding-bottom: 40px;
}

.formOutter .approvalForm {
	border: 1px solid lightgray;
	background-color: white;
	padding: 8px;
	margin-top: 8px;
}

.formOutter .approvalForm .approvalBtn {
	padding: 10px 0;
	height: 50px;
	width: 350px;
	margin: 0 auto;
}

.mini-toolbar {
	background: white;
}

.approvalResultTable {
	width: 100%;
	border-collapse: collapse;
}

.approvalResultTable td {
	border: 1px solid lightgray !important;
}

.approvalResultTable .appResultTitle {
	width: 80px;
	font-weight: bold;
	text-align: center;
}

.versionPan {
	float: right;
	z-index: 9999;
	line-height: 30px;
	position: absolute;
	right: 1px;
	top: 16px;
	display: inline-block;
	width: 220px;
	white-space: nowrap;
}

.versionPan .versionTitle {
	font-size: 12px;
	font-weight: normal;
	font-style: normal;
	display: inline-block;
	margin-left: 8px;
	width: 55px;
}

.commentStyle {
	margin-left: 20px;
	font-size: 12px;
}
.notice{
	padding:6px;
	color: #8a6d3b;
	  background-color: #fcf8e3;
	  border:1px solid #faebcc;
}
.isNotValidAttch{
	background-color: #fcf8e3;
}
.pageTitle{
	border-left: 4px solid #2459aa
}
</style>
<script type="text/javascript">
</script>
</head>
<body>
	<div id="toolbar1" class="mini-toolbar"
		style="padding: 2px; border-width: 0 0 1px 0; border-color: #C9C9C9">
		<table style="width: 100%;">
			<tr>
				<td>
					<a class="mini-button" id="editBtn" iconCls="icon-edit" plain="true" onclick="editPhaseInEdit">编辑</a>
					<a class="mini-button" id="saveBtn" iconCls="icon-save" plain="true" onclick="save">保存</a>
					<a class="mini-button" id="cancelBtn" iconCls="icon-cancel" plain="true" onclick="cancelEdit">取消</a>
					<a class="mini-button" id="uploadFileBtn" iconCls="icon-clip" plain="true" onclick="openFileUpload">上传附件</a>
					<!-- <a class="mini-button" id="deleteBtn" iconCls="icon-cancel"
						plain="true" onclick="deleteRecords">删除</a> -->
					<span class="separator"></span>
					<a class="mini-button" id="refreshBtn" iconCls="icon-reset" plain="true" onclick="refreshThisPage">刷新</a>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit" id="contentFormFit">
		<div class="formOutter">
			<table class="frametable"
				style="border-collapse: collapse; border-width: 0;">
				<tr>
					<td>
						<div class="taskForm" style="margin-top: 8px; position: relative;">
							<div class="pageTitle">
								<span style="margin: 0"></span>
								<p id="formTitleId"
									style="margin: 0; font-size: 16px; color: gray;"></p>
							</div>
							<div id="contentFormPan" class="mini-panel" title="form"
								showHeader="false" style="width: 100%;" borderStyle="border:0;"
								bodyStyle="padding:0;" showCollapseButton="true"
								onload="contentFormOnload"></div>
							<div class="notice">
								请先保存数据，然后上传附件！
							</div>
							<div id="attchPan0" class="mini-panel" iconCls="icon-clip"
								title="音影附件(支持格式：mp3、wav、ogg;mp4、webm、mpeg4)" style="width: 100%; margin-top: 10px;"
								showCollapseButton="false" visible="false"
								bodyStyle="padding:0;">
								<div id="grid_attch0" class="mini-datagrid gridFull"
									showColumns="true" pageSize="100" borderStyle="border-width:0"
									idField="ID" allowHeaderWrap="true" allowSortColumn="true"
									width="100%" showEmptyText="true" emptyText="没有音影附件"
									showPager="false" ondrawcell="onDrawCell" ondrawgroup=""
									allowCellEdit="true" allowCellSelect="true"
									editNextOnEnterKey="true" editNextRowCell="true">
									<div property="columns">
										<div type="indexcolumn"></div>
										<div field="fileName" width="100%" headerAlign="center">文件名</div>
										<div name="fileTitle" field="fileTitle" width="110px"
											headerAlign="center">
											标题<input property="editor" class="mini-textbox"
												emptyText="请输入标题" onvaluechanged="changTitle"
												errorMode="icon" />
										</div>
										<div name="note" field="note" width="140px"
											headerAlign="center">
											描述<input property="editor" class="mini-textbox"
												emptyText="请输入描述" onvaluechanged="changNote"
												errorMode="icon" />
										</div>
										<div field="creater" width="60px" headerAlign="center">上传人</div>
										<div field="createTime" width="110px"
											dateFormat="yyyy-MM-dd HH:mm" headerAlign="center">上传时间</div>
										<div name="delete" field="delete" width="40px"
											headerAlign="center"></div>
										<!-- <div name="emptyCol" width='100%' headerAlign="center"
											align="center" cellStyle="padding:0;"></div> -->
									</div>
								</div>
							</div>
							<div id="attchPan1" class="mini-panel" iconCls="icon-clip"
								title="普通附件" style="width: 100%; margin-top: 10px;"
								expanded="true" showCollapseButton="false"
								bodyStyle="padding:0;">
								<div id="grid_attch" class="mini-datagrid gridFull"
									showColumns="true" pageSize="100" borderStyle="border-width:0"
									idField="ID" allowHeaderWrap="true" allowSortColumn="true"
									width="100%" showEmptyText="true" emptyText="没有附件"
									showPager="false" ondrawcell="onDrawCell" ondrawgroup="" 
									allowCellEdit="true" allowCellSelect="true" 
									editNextOnEnterKey="true" editNextRowCell="true">
									<div property="columns">
										<div type="indexcolumn"></div>
										<div field="fileName" width="100%" headerAlign="center">文件名</div>
										<div name="fileTitle" field="fileTitle" width="110px"
											headerAlign="center">标题<input property="editor" class="mini-textbox"
											emptyText="请输入标题" onvaluechanged="changTitle"
											errorMode="icon" /></div>
										<div name="note" field="note" width="140px" headerAlign="center">描述<input property="editor" class="mini-textbox"
											emptyText="请输入描述" onvaluechanged="changNote"
											errorMode="icon" /></div>
										<div field="creater" width="60px" headerAlign="center">上传人</div>
										<div field="createTime" width="110px"
											dateFormat="yyyy-MM-dd HH:mm" headerAlign="center">上传时间</div>
										<div name="delete" field="delete" width="40px" headerAlign="center"></div>
										<!-- <div name="emptyCol" width='100%' headerAlign="center"
											align="center" cellStyle="padding:0;"></div> -->
									</div>
								</div>
							</div>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		
		var rootPath = '${rootPath}/';
		var userName = '${userName}';
		var id = '${id}';
		var uuid = '${uuid}';
		var pagePath = '${pagePath}';
		var action = '${action}';
		var business = '${business}';
		var type = '${type}';
		var state = '${state}';//评估、审核状态
		var orgNo = '${orgNo}';
		var fileServer = '${fileServer}';
		var configStr = "${configStr}";
		
		var onlyCheck = true;//只能查看模式
		
		var deleteBtn = mini.get("deleteBtn");
		var grid_attch0 = mini.get("grid_attch0");
		var grid_attch = mini.get("grid_attch");
		var contentFormPan = mini.get("contentFormPan");
		var editBtn = mini.get("editBtn");
		var saveBtn = mini.get("saveBtn");
		var uploadFileBtn = mini.get("uploadFileBtn");
		var refreshBtn = mini.get("refreshBtn");
		var cancelBtn = mini.get("cancelBtn");
		/* 初始化 */
		$(function() {
			$('#formTitleId').html('${titleName}');
			contentFormPan.setUrl(rootPath + pagePath);
			loadPage();
			if(business == "case"){
				$('#attchPan0').show();
			}else{
				$('#attchPan0').hide();
			}
		});
		function loadPage(){
			if (action === "new") {
				newPhase();
			} else if (action === "edit") {
				editPhase();
			} else if (action === "check") {
				checkPhase();
			}
		}
		
		//>>>>>>>>>>>>>>>>>>>>>>>>>>排版及接口<<<<<<<<<<<<<<<<<<<<<<<<<
		function contentFormOnload() {
			var iframeHeight = $(contentFormPan.getBodyEl()).find("iframe")[0].contentWindow.document
					.getElementById("dataForm").scrollHeight;
			contentFormPan.setHeight(iframeHeight + 30 + "px");
		}
		function getUserName() {
			return userName;
		}
		function getAction() {
			return action;
		}
		function getRootPath() {
			return rootPath;
		}
		function getType() {
			return type;
		}
		function getConfigStr() {
			return configStr;
		}
		function getId() {
			if(id){
				return id;
			}else{
				return 0;
			}
		}
		function getUuid() {
			if(uuid){
				return uuid;
			}else{
				return 0;
			}
		}
		function getOrgNo() {
			if(orgNo){
				return orgNo;
			}else{
				return 0;
			}
		}
		function getFileServer() {
			return fileServer;
		}
		function hideAtt(){
			uploadFileBtn.hide();
			$(".notice").hide();
			$("#attchPan1").hide();
		}

		/*>>>>>>>>>>>>>>>>>>>>>>>>>操作行为模式<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/
		/* 新增模式 */
		function newPhase() {
			if(!'${titleName}'){
				$(".pageTitle").hide();
			}
			editBtn.hide();
			saveBtn.show();
			uploadFileBtn.disable();
			refreshBtn.show();
			cancelBtn.show();
			onlyCheck = false;
		}
		/* 编辑模式 */
		function editPhase() {
			saveBtn.hide();
			cancelBtn.hide();
			editBtn.show();
			uploadFileBtn.disable();
			refreshBtn.hide();
			cancelBtn.hide();
			
			grid_attch.hideColumn("delete");
			grid_attch0.hideColumn("delete");
			
			$(".notice").hide();

			if(business == "case"){
				loadAttachment(attCheckPhase);
			}
			onlyCheck = true;
		}
		
		/* 查看模式 */
		function checkPhase() {
			editBtn.hide();
			saveBtn.hide();
			cancelBtn.hide();
			uploadFileBtn.hide();
			refreshBtn.show();
			grid_attch.hideColumn("delete");
			grid_attch0.hideColumn("delete");

			$(".notice").hide();

			if(business == "case"){
				loadAttachment(attCheckPhase);
			}
			onlyCheck = true;
		}

		/* 编辑模式--编辑中 */
		function editPhaseInEdit() {
			var subpageWindow = $(contentFormPan.getBodyEl()).find("iframe")[0].contentWindow;
			inputModel(subpageWindow.mini, subpageWindow.body,
					subpageWindow.form);

			editBtn.hide();
			cancelBtn.show();
			saveBtn.show();
			uploadFileBtn.enable();
			grid_attch.showColumn("delete");
			grid_attch0.showColumn("delete");
			attEditPhase();
			refreshBtn.hide();
			onlyCheck = false;
			if(typeof subpageWindow.onlyCheck != "undefined"){
				subpageWindow.onlyCheck = false;
			}
		}
		/* 编辑模式--查看中 */
		function editPhaseInCheck() {
			var subpageWindow = $(contentFormPan.getBodyEl()).find("iframe")[0].contentWindow;
			labelModel(subpageWindow.form);

			editBtn.show();
			cancelBtn.hide();
			saveBtn.hide();
			uploadFileBtn.disable();
			refreshBtn.hide();
			grid_attch.hideColumn("delete");
			grid_attch0.hideColumn("delete");
			attCheckPhase();
			onlyCheck = true;
			if(typeof subpageWindow.onlyCheck != "undefined"){
				subpageWindow.onlyCheck = true;
			}
		}
		/* 取消编辑 */
		function cancelEdit() {
			var subpageWindow = $(contentFormPan.getBodyEl()).find("iframe")[0].contentWindow;
			//var data = subpageWindow.form.getData();
			//subpageWindow.form.setData(data);
			subpageWindow.form.setData(subpageWindow.dataOri);
			labelModel(subpageWindow.form);
			
			saveBtn.hide();
			editBtn.show();
			cancelBtn.hide();
			uploadFileBtn.disable();
			refreshBtn.hide();
			grid_attch.hideColumn("delete");
			grid_attch0.hideColumn("delete");
			$(".notice").hide();
			attCheckPhase();
			onlyCheck = true;
			if(typeof subpageWindow.onlyCheck != "undefined"){
				subpageWindow.onlyCheck = true;
			}
			
			//删除刚才提交未保存的附件
			/* var nos = getTempAttch();
			if(nos){
				deleteTempAttch(nos);
			} */
			
		}
		/* 附件编辑模式 */
		function attEditPhase(){
			var rows0 = grid_attch0.findRows(function(row){
			    return true;
			});
			for(var i=0,length=rows0.length; i<length; i++){
				var nameInput = grid_attch0.getCellEditor ('fileTitle', rows0[i]);
				var desInput = grid_attch0.getCellEditor ('note', rows0[i]);
				nameInput.enable();
				desInput.enable();
				//grid_attch0.beginEditCell(rows[i]);//启动行编辑
			}
			var rows = grid_attch.findRows(function(row){
			    return true;
			});
			for(var i=0,length=rows.length; i<length; i++){
				var nameInput = grid_attch.getCellEditor ('fileTitle', rows[i]);
				var desInput = grid_attch.getCellEditor ('note', rows[i]);
				nameInput.enable();
				desInput.enable();
				//grid_attch.beginEditCell(rows[i]);//启动行编辑
			}
		}
		/* 附件查看模式 */
		function attCheckPhase(){
			var rows0 = grid_attch0.findRows(function(row){
			    return true;
			});
			for(var i=0,length=rows0.length; i<length; i++){
				var nameInput = grid_attch0.getCellEditor ('fileTitle', rows0[i]);
				var desInput = grid_attch0.getCellEditor ('note', rows0[i]);
				nameInput.disable();
				desInput.disable();
				//grid_attch0.cancelEdit();//取消行编辑
			}
			var rows = grid_attch.findRows(function(row){
			    return true;
			});
			for(var i=0,length=rows.length; i<length; i++){
				var nameInput = grid_attch.getCellEditor ('fileTitle', rows[i]);
				var desInput = grid_attch.getCellEditor ('note', rows[i]);
				nameInput.disable();
				desInput.disable();
				//grid_attch.cancelEdit();//取消行编辑
			}
		}

		/* 加载附件 */
		function loadAttachment(attStatFun) {
			grid_attch.load(rootPath + "attach/list/" + business + "/"+id);
			grid_attch.load({},function(){
				attStatFun()
			}); 
			if(business == "case"){
				grid_attch0.load(rootPath + "attach/list/" + business + "_video/"+id);
				grid_attch0.load({},function(){
					attStatFun()
				}); 
			}
			
			
		}
		/* 隐藏附件列表 */
		function hideAttchPan() {
			$('#attchPan1').hide();
			$('#attchPan2').hide();
			$('.formOutter').attr("width", "700px");
		}
		/* 附件列表渲染 */
		function onDrawCell(e) {
			var field = e.field;
			var row = e.row;
			var id = row.id;
			
			if (field == "delete") {
				if (state == '0' || state == '2' || state == '4') {
					e.cellHtml = "<a class='aTagUnderLine' href='javascript:deleteAttch("
						+ id + ")'>删除</a>";
				}
			}
			if (field == "state") {
				var value = e.value;
				if(value == 0){
					/* e.cellHtml = "未提交&nbsp;<a class='aTagUnderLine' href='javascript:submintAttch(\""
						+ attchNo + "\")'>[点击提交]</a>"; */
					e.cellHtml = "未提交";
				}
			}
			if (field == "fileName") {
				var name = row.fileName;
				var type = row.fileType;
				if (type) {
					type = type.toLowerCase();
				}
				
				var html = "";
				switch (type) {
				case ".doc":
					html = "<span class='fileIcons docIcon'></span>";
					break;
				case ".docx":
					html = "<span class='fileIcons docxIcon'></span>";
					break;
				case ".xls":
					html = "<span class='fileIcons xlsIcon'></span>";
					break;
				case ".xlsx":
					html = "<span class='fileIcons xlsxIcon'></span>";
					break;
				case ".pdf":
					html = "<span class='fileIcons pdfIcon'></span>";
					break;
				case ".jpeg":
					html = "<span class='fileIcons jpegIcon'></span>";
					break;
				case ".jpg":
					html = "<span class='fileIcons jpgIcon'></span>";
					break;
				case ".bmp":
					html = "<span class='fileIcons bmpIcon'></span>";
					break;
				case ".png":
					html = "<span class='fileIcons pngIcon'></span>";
					break;
				case ".rar":
					html = "<span class='fileIcons rarIcon'></span>";
					break;
				default:
					html = "<span class='fileIcons normalIcon'></span>";
					break;
				}
				var url = "<c:url value='/attach/download/' />" + id;
				e.cellHtml = html + "<a target='_blank' class='aTagUnderLine' href='"+url+"'>"
						+ name + "</a>";
			}
		}
		function onDrawGroup(e) {    
			var groupId = e.group.id;
        	var str = "版本：" + e.value;
        	if(groupId == 'g1'){
        		str += '（当前最新版本）';
        	}
        	e.cellHtml = str;
        }

		/* form查看模式 */
		function labelModel(_form) {
			var fields = _form.getFields();
			for (var i = 0, l = fields.length; i < l; i++) {
				var c = fields[i];
				if (c.setReadOnly)
					c.setReadOnly(true);
				if (c.setIsValid)
					c.setIsValid(true);
				if (c.addCls)
					c.addCls("asLabel");
			}
		}
		/* form编辑模式 */
		function inputModel(_mini, _body, _form) {
			var fields = _form.getFields();
			for (var i = 0, l = fields.length; i < l; i++) {
				var c = fields[i];
				if (c.setReadOnly)
					c.setReadOnly(false);
				if (c.removeCls)
					c.removeCls("asLabel");
			}
			_mini.repaint(_body);
		}

		/* 刷新当前页面 */
		function refreshThisPage() {
			loadPage();
		}

		//>>>>>>>>>>>>>>>>>>>>>CRUD<<<<<<<<<<<<<<<<<<<<<<<<<<
		/* 保存数据 */
		function save() {
			var subWindow = $(contentFormPan.getBodyEl()).find("iframe")[0].contentWindow;
			var form = subWindow.packData();
			form.validate();
			if (form.isValid() == false) {
				parent.mini.alert("请填写必要信息后再保存!");
				return;
			}
			var formData = form.getData();
			var data = mini.encode(formData);
			var url = null;
			if (action == "new") {
				id = 0;
			}
			if(business == 'msg/mng'){
				url = '<c:url value="/'+business+'/save/"></c:url>'+uuid;
			}else{
				url = '<c:url value="/'+business+'/save/"></c:url>'+action;
			}
			var messageid = mini.loading("保存中...", "Loading");
			$.ajax({
				url : url,
				type : "post",
				dataType : 'json',
				data : {
					"formData" : data
				},
				success : function(text) {
					if(!text){
						top.commonTools.showTip("保存失败", 2);
						return;
					}
					var refMap = mini.decode(text);
					var isSuccess = refMap.isSuccess;
					var info = refMap.info;
					if(isSuccess){
						action = "edit";
						approvalState = '1';
						top.commonTools.showTip("保存成功", 1);
						//设为只读模式
						editPhaseInCheck();
					}else{
						top.commonTools.showTip(info, 2);
					}
					//editPhase();
					subWindow.dataOri = formData;
				},
				complete : function(XMLHttpRequest, textStatus) {
					if (messageid) {
						mini.hideMessageBox(messageid);
					}
					//如果上级是列表，则刷新
					if (parent.reloadList) {
						parent.reloadList();
					}
					if (parent.parent.reloadList) {
						parent.parent.reloadList();
					}
				},
				error : function() {
					top.commonTools.showTip("操作发生错误", 2);
				}
			});
		}

		//>>>>>>>>>>>>>>>>>>>>>>>>附件<<<<<<<<<<<<<<<<<<<<<<<<<<
		/* 打开附件页面 */
		function openFileUpload() {
			var url = '<c:url value="/attach/"></c:url>' + business + '/' + id;
			if (business == "case") {
				mini.showMessageBox({
					showHeader : false,
					width : 300,
					title : "请选择附件类型：音影附件or普通附件",
					buttons : [ "音影", "普通", "cancel" ],
					message : "请选择附件类型：音影附件/普通附件",
					iconCls : "mini-messagebox-info",
					callback : function(action) {
						if(action == "音影"){
							url = '<c:url value="/attach/"></c:url>' + business + '_video/' + id;
							open(url);
						}else if(action == "普通"){
							open(url);
						}
					}
				});
			}else{
				open(url);
			}
		}
		function open(url){
			mini.open({
				url : url,
				title : "上传附件",
				width : 600,
				height : 400,
				ondestroy : function(action) {
					if (action == "ok") {
						top.commonTools.showTip("附件上传成功！", 1);
						loadAttachment(editPhaseInEdit);
					}
				}
			});
		}
		/* 修改标题 */
		function changTitle(e) {
			var value = e.value;
			var isValid = this.validate();
			if (!isValid) {
				top.commonTools.showTip("输入有误", 2);
				this.setValue();
				return;
			}
			var row = grid_attch.getSelected();
			var id = row.id;
			$.ajax({
				url : '<c:url value="/attach/update/field"></c:url>',
				type : "post",
				dataType : 'json',
				data : {
					"id" : id,
					"fileTitle" : value
				},
				success : function(text) {
					if (text && text == true) {
						grid_attch.updateRow(row, {
							"AttchmntFullName" : value
						});
						grid_attch.reload();
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
				},
				error : function() {
					mini.alert("附件标题保存出错，请重新输入。如果问题仍不能解决，请联系管理员。");
				}
			});
		}
		/* 修改描述 */
		function changNote(e) {
			var value = e.value;
			var isValid = this.validate();
			if (!isValid) {
				top.commonTools.showTip("输入有误", 2);
				this.setValue();
				return;
			}

			var row = grid_attch.getSelected();
			var id = row.id;
			$.ajax({
				url : '<c:url value="/attach/update/field"></c:url>',
				type : "post",
				dataType : 'json',
				data : {
					"id" : id,
					"note" : value
				},
				success : function(text) {
					if (text && text == true) {
						grid_attch.updateRow(row, {
							"Description" : value
						});
						grid_attch.reload();
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
				},
				error : function() {
					mini.alert("附件描述保存出错，请重新输入。如果问题仍不能解决，请联系管理员。");
				}
			});
		}
		/* 删除一条附件 */
		function deleteAttch(id) {
			var url = "<c:url value='/attach/clear/' />" + id;
			mini.confirm("确认删除？", "是", function(action) {
				if (action == "ok") {
					var messageid = mini.loading("操作中...", "Loading");
					$.ajax({
						url : url,
						type : "post",
						dataType : 'json',
						success : function(text) {
							if (text && text == true) {
								top.commonTools.showTip("删除成功", 1);
								grid_attch.reload();
							} else {
								top.commonTools.showTip("删除失败", 2);
							}
						},
						complete : function(XMLHttpRequest, textStatus) {
							if (messageid) {
								mini.hideMessageBox(messageid);
							}
						},
						error : function() {
							top.commonTools.showTip("操作发生错误", 2);
						}
					});
				} else {
					return;
				}
			});
		}

		/* 提交附件 */
		function submintAttch(attchNos) {
			$.ajax({
				url : '<c:url value="/attchUpdate/setValid"></c:url>',
				type : "post",
				dataType : 'json',
				data : {
					"attchmentNos" : attchNos
				},
				success : function(text) {
					if (text && text == true) {
						top.commonTools.showTip("操作成功", 1);
						grid_attch.reload();
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					//grid_attch.reload();
				},
				error : function() {
					mini.alert("提交附件出错，请重新修改后保存。如果问题仍不能解决，请联系管理员。");
				}
			});
		}
		/* 获取新添加的附件 */
		function getTempAttch() {
			var rows = grid_attch.findRows(function(row) {
				if (row.CatalogNo == 'temp')
					return true;
			});
			var nos = '';
			for (var i = 0, length = rows.length; i < length; i++) {
				var attNo = rows[i].AttchmntNo;
				if (attNo) {
					if (i != 0) {
						nos += '$';
					}
					nos += attNo;
				}
			}
			return nos;
		}

		/* 删除未保存的附件 */
		function deleteTempAttch(attchNos) {
			var url = "<c:url value='/attchUpdate/deletes' />";
			var messageid = mini.loading("附件删除中...", "Loading");
			$.ajax({
				url : url,
				type : "post",
				dataType : 'json',
				data : {
					"attchmentNos" : attchNos
				},
				success : function(text) {
					if (typeof text == "boolean" && text == true) {
						//top.commonTools.showTip("删除成功", 1);
						grid_attch.reload();
					} else {
						top.commonTools.showTip("附件删除失败", 2);
					}
				},
				complete : function(XMLHttpRequest, textStatus) {
					if (messageid) {
						mini.hideMessageBox(messageid);
					}
				},
				error : function() {
					top.commonTools.showTip("删除附件发生错误", 2);
				}
			});
		}
		//>>>>>>>>>>>>>>返回上级<<<<<<<<<<<<<<<<<<<<<<
		function reback() {
			if (parent.loadSelected) {
				parent.isBase = true;
				parent.loadSelected();
			} else if (parent.parent.loadSelected) {
				parent.parent.isBase = true;
				parent.parent.loadSelected();
			}
		}
	</script>
</body>
</html>
